package com.st.springts.service;

import com.st.springts.demos.web.Page;
import com.st.springts.demos.web.Result;
import com.st.springts.entity.User;
import com.st.springts.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.List;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;
    public void insertUser(User user){
        userMapper.insert(user);
    }

    public void deleteUser(Integer id){
        userMapper.delete(id);
    }

    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    public void batchDeleteUser(List<Integer> ids) {
        for (Integer id : ids) {
            userMapper.batchDeleteUser(id);
        }

    }

    public List<User> selectAll() {
    return userMapper.selectAll();
    }

    public User selectById(Integer id) {
     return    userMapper.selectById(id);
    }

    public List<User> selectByMore(String username, String name) {
        return userMapper.selectByMore(username,name);
    }

    public List<User> selectByMo(String username, String name) {
        return userMapper.selectByMo(username,name);
    }

    public Page<User> selectByPage(Integer pageNum,Integer pageSize,String username, String name) {
        Integer skipNum = (pageNum-1)*pageSize;

        Page<User> page = new Page<>();
        List<User> userList =userMapper.selectByPage(skipNum,pageSize,username,name);
        Integer total = userMapper.selecCounttByPage(username, name);
        page.setTotal(total);
        page.setList(userList);

        return page;
    }

    public Integer selectByUsername(String username) {

        return userMapper.selectByUsername(username);
    }

    public String selectab(Integer id) {
        User selectab = userMapper.selectab(id);
        String s = selectab.getUsername() + selectab.getPassword();
        return s;
    }

    public void selectaa() {


    List<Double>  aa = userMapper.selectaa();
  Double  a0=aa.get(0);
        System.out.println(aa.get(0));
        System.out.println(aa.get(1));
        System.out.println(aa.get(2));
        System.out.println(aa.get(3));
        if(1==1 && a0==141){
            System.out.println(a0);
        }



//        System.out.println(aa);
//        double a0=aa[0];
//        double a1=aa[1];
//        double a2=aa[2];
//        double a3=aa[3];
//        System.out.println(a0);
//        System.out.println(a1);
//        System.out.println(a2);
//        System.out.println(a3);

    }
}
